package com.zf.lease.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zf.common.annotation.Log;
import com.zf.common.core.controller.BaseController;
import com.zf.common.core.domain.AjaxResult;
import com.zf.common.enums.BusinessType;
import com.zf.lease.domain.OrderMsg;
import com.zf.lease.service.IOrderMsgService;
import com.zf.common.utils.poi.ExcelUtil;
import com.zf.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/system/msg")
public class OrderMsgController extends BaseController
{
    @Autowired
    private IOrderMsgService orderMsgService;

    /**
     * 根据customerI和roomId得到单个预约信息
     */
    @PreAuthorize("@ss.hasPermi('system:msg:query')")
    @GetMapping("/getMsgByKey/{customerId}/{roomId}")
    public AjaxResult getMsgByKey(@PathVariable("customerId") Long customerId,@PathVariable("roomId") Long roomId)
    {
        return success(orderMsgService.selectOrderMsgByKey(customerId,roomId));
    }

    /**
     * 查询预约信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:msg:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderMsg orderMsg)
    {
        startPage();
        List<OrderMsg> list = orderMsgService.selectOrderMsgList(orderMsg);
        return getDataTable(list);
    }

    /**
     * 导出预约信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:msg:export')")
    @Log(title = "预约信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderMsg orderMsg)
    {
        List<OrderMsg> list = orderMsgService.selectOrderMsgList(orderMsg);
        ExcelUtil<OrderMsg> util = new ExcelUtil<OrderMsg>(OrderMsg.class);
        util.exportExcel(response, list, "预约信息数据");
    }

    /**
     * 获取预约信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:msg:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return success(orderMsgService.selectOrderMsgByCustomerId(customerId));
    }

//    /**
//     * 新增预约信息
//     */
//    @PreAuthorize("@ss.hasPermi('system:msg:add')")
//    @Log(title = "预约信息", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody OrderMsg orderMsg)
//    {
//        return toAjax(orderMsgService.insertOrderMsg(orderMsg));
//    }
    /**
     * 新增预约信息
     */
    @PreAuthorize("@ss.hasPermi('system:msg:add')")
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    public int add(@RequestBody OrderMsg orderMsg)
    {
        return orderMsgService.insertOrderMsg(orderMsg);
    }

    /**
     * 修改预约信息
     */
    @PreAuthorize("@ss.hasPermi('system:msg:edit')")
    @Log(title = "预约信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderMsg orderMsg)
    {
        return toAjax(orderMsgService.updateOrderMsg(orderMsg));
    }

    /**
     * 删除预约信息
     */
    @PreAuthorize("@ss.hasPermi('system:msg:remove')")
    @Log(title = "预约信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(orderMsgService.deleteOrderMsgByCustomerIds(customerIds));
    }
    /**
     * 根据customerI和roomId删除预约信息
     */
    @DeleteMapping("/{customerId}/{roomId}")
    public AjaxResult removeByKey(@PathVariable("customerId") Long[] customerId,@PathVariable("roomId") Long[] roomId)
    {
        for (int i = 0; i < customerId.length; i++) {
            OrderMsg orderMsg = new OrderMsg();
            orderMsg.setCustomerId(customerId[i]);
            orderMsg.setRoomId(roomId[i]);
            orderMsg.toString();
        }
            return toAjax(orderMsgService.deleteOrderMsgByKey(customerId,roomId));
    }
}
